package listbyorder.access101_200.test122;

/**
 * @author code_yc
 * @version 1.0
 * @date 2020/6/8 13:26
 */
public class Solution2 {

    // 思路提样，没有用max方法
    public int maxProfit(int[] prices) {
        // 首先进行边界条件判断
        if(prices == null || prices.length < 2) return 0;
        // 将给定的价格数组改造为收益数组
        int res = 0;
        int cur = 0;
        for(int i = 0; i < prices.length - 1; i++){
            cur = prices[i + 1] - prices[i];
            res += cur > 0 ? cur : 0 ;
        }
        return res;
    }
}
